<?php

/*
 * This file is part of the gedongdong/laravel_rbac_permission.
 *
 * (c) gedongdong <gedongdong2010@163.com>
 *
 * This source file is subject to the MIT license that is bundled
 * with this source code in the file LICENSE.
 */

namespace App\Http\Controllers\Admin;

use App\Http\Controllers\Controller;
use App\Http\Models\UserAmountLog;
use App\Http\Models\Users;
use App\Http\Models\ZhyReport;
use Illuminate\Http\Request;
use App\Library\Response;
use Illuminate\Support\Facades\DB;
use Illuminate\Database\QueryException;
use Illuminate\Support\Facades\Validator;
// use App\Validate\ReportUpdateValidate;

use Maatwebsite\Excel\Facades\Excel;

class WaterPipeController extends Controller
{

    public $province1 =  '';
    public $province2 =  '';
    public $province3 =  '';
    public $productCodeList = [];

    public function __construct()
    {
        $this->province1 =  '浙江省-江苏省-上海市-安徽省';
        $this->province2 =  '北京市-河北省-天津市-山东省-河南省-湖北省-湖南省-江西省-福建省';
        $this->province3 =  '广东省-陕西省-山西省-辽宁省-吉林省-广西壮族自治区-重庆市-四川省-云南省-贵州省-黑龙江省-海南省-甘肃省-西藏自治区-宁夏回族自治区-内蒙古自治区-青海省';
        $this->productCodeList = [
            '蛇皮水管4分-10厘米'=>[
                'accessoryPrice' => 0,//配件价格
                'price' => 0,//价格
                'packFee' => 1,//打包费
                'expressFeeArr' => [//快递费
                    $this->province1 => 2.8,
                    $this->province2 => 2.8,
                    $this->province3 => 2.8
                ],
                'sellingPrice' => 2.8,//售价
            ],
            '蛇皮水管4分-5米'=>[
                'accessoryPrice' => 0.26,//配件价格
                'price' => 2.41,//价格
                'packFee' => 1.5,//打包费
                'expressFeeArr' => [//快递费
                    $this->province1 => 2.8,
                    $this->province2 => 2.8,
                    $this->province3 => 2.8
                ],
                'sellingPrice' => 8.67,//售价
            ],
            '蛇皮水管4分-10米'=>[
                'accessoryPrice' => 0.26,//配件价格
                'price' => 4.83,//价格
                'packFee' => 1.5,//打包费
                'expressFeeArr' => [//快递费
                    $this->province1 => 2.8,
                    $this->province2 => 2.8,
                    $this->province3 => 2.8
                ],
                'sellingPrice' => 12.38,//售价
            ],
            '蛇皮水管4分-15米'=>[
                'accessoryPrice' => 0.26,//配件价格
                'price' => 7.24,//价格
                'packFee' => 1.5,//打包费
                'expressFeeArr' => [//快递费
                    $this->province1 => 2.8,
                    $this->province2 => 2.8,
                    $this->province3 => 2.8
                ],
                'sellingPrice' => 15.95,//售价
            ],
            '蛇皮水管4分-20米'=>[
                'accessoryPrice' => 0.26,//配件价格
                'price' => 9.66,//价格
                'packFee' => 1.5,//打包费
                'expressFeeArr' => [//快递费
                    $this->province1 => 3.3,
                    $this->province2 => 3.3,
                    $this->province3 => 3.3
                ],
                'sellingPrice' => 19.08,//售价
            ],
            '蛇皮水管4分-25米'=>[
                'accessoryPrice' => 0.26,//配件价格
                'price' => 12.07,//价格
                'packFee' => 1.5,//打包费
                'expressFeeArr' => [//快递费
                    $this->province1 => 3.3,
                    $this->province2 => 3.3,
                    $this->province3 => 3.3
                ],
                'sellingPrice' => 22.71,//售价
            ],
            '蛇皮水管4分-30米'=>[
                'accessoryPrice' => 0.26,//配件价格
                'price' => 14.49,//价格
                'packFee' => 1.5,//打包费
                'expressFeeArr' => [//快递费
                    $this->province1 => 3.3,
                    $this->province2 => 3.3,
                    $this->province3 => 3.3
                ],
                'sellingPrice' => 25.39,//售价
            ],
            '蛇皮水管4分-35米'=>[
                'accessoryPrice' => 0.26,//配件价格
                'price' => 16.9,//价格
                'packFee' => 1.5,//打包费
                'expressFeeArr' => [//快递费
                    $this->province1 => 4,
                    $this->province2 => 4,
                    $this->province3 => 4
                ],
                'sellingPrice' => 29.83,//售价
            ],
            '蛇皮水管4分-40米'=>[
                'accessoryPrice' => 0.26,//配件价格
                'price' => 19.32,//价格
                'packFee' => 1.5,//打包费
                'expressFeeArr' => [//快递费
                    $this->province1 => 4,
                    $this->province2 => 4,
                    $this->province3 => 4
                ],
                'sellingPrice' => 33.79,//售价
            ],
            '蛇皮水管4分-45米'=>[
                'accessoryPrice' => 0.26,//配件价格
                'price' => 19.05,//价格
                'packFee' => 1.5,//打包费
                'expressFeeArr' => [//快递费
                    $this->province1 => 4,
                    $this->province2 => 4,
                    $this->province3 => 4
                ],
                'sellingPrice' => 36.39,//售价
            ],
            '蛇皮水管4分-50米'=>[
                'accessoryPrice' => 0.26,//配件价格
                'price' => 24.14,//价格
                'packFee' => 1.5,//打包费
                'expressFeeArr' => [//快递费
                    $this->province1 => 7.36,
                    $this->province2 => 8.8,
                    $this->province3 => 10.4
                ],
                'sellingPrice' => 42.39,//售价
            ],
            '蛇皮水管4分-55米'=>[
                'accessoryPrice' => 0.26,//配件价格
                'price' => 26.56,//价格
                'packFee' => 1.5,//打包费
                'expressFeeArr' => [//快递费
                    $this->province1 => 7.36,
                    $this->province2 => 8.8,
                    $this->province3 => 10.4
                ],
                'sellingPrice' => 47.87,//售价
            ],
            '蛇皮水管4分-60米'=>[
                'accessoryPrice' => 0.26,//配件价格
                'price' => 28.97,//价格
                'packFee' => 1.5,//打包费
                'expressFeeArr' => [//快递费
                    $this->province1 => 7.36,
                    $this->province2 => 8.8,
                    $this->province3 => 10.4
                ],
                'sellingPrice' => 52.9,//售价
            ],
            '蛇皮水管4分-70米'=>[
                'accessoryPrice' => 0.26,//配件价格
                'price' => 33.8,//价格
                'packFee' => 1.5,//打包费
                'expressFeeArr' => [//快递费
                    $this->province1 => 8.2,
                    $this->province2 => 10,
                    $this->province3 => 12
                ],
                'sellingPrice' => 59.99,//售价
            ],
            '蛇皮水管4分-80米'=>[
                'accessoryPrice' => 0.26,//配件价格
                'price' => 38.63,//价格
                'packFee' => 1.5,//打包费
                'expressFeeArr' => [//快递费
                    $this->province1 => 9.04,
                    $this->province2 => 11.2,
                    $this->province3 => 13.6
                ],
                'sellingPrice' => 65.79,//售价
            ],
            '蛇皮水管4分-90米'=>[
                'accessoryPrice' => 0.26,//配件价格
                'price' => 43.46,//价格
                'packFee' => 1.5,//打包费
                'expressFeeArr' => [//快递费
                    $this->province1 => 9.04,
                    $this->province2 => 11.2,
                    $this->province3 => 13.6
                ],
                'sellingPrice' => 71.39,//售价
            ],
            '蛇皮水管4分-100米'=>[
                'accessoryPrice' => 0.26,//配件价格
                'price' => 48.29,//价格
                'packFee' => 1.5,//打包费
                'expressFeeArr' => [//快递费
                    $this->province1 => 9.88,
                    $this->province2 => 12.4,
                    $this->province3 => 15.2
                ],
                'sellingPrice' => 80.19,//售价
            ],
    
    
            '蛇皮水管6分-10厘米'=>[
                'accessoryPrice' => 0,//配件价格
                'price' => 0,//价格
                'packFee' => 1,//打包费
                'expressFeeArr' => [//快递费
                    $this->province1 => 2.8,
                    $this->province2 => 2.8,
                    $this->province3 => 2.8
                ],
                'sellingPrice' => 4.8,//售价
            ],
            '蛇皮水管6分-5米'=>[
                'accessoryPrice' => 0.6,//配件价格
                'price' => 3.26,//价格
                'packFee' => 1.5,//打包费
                'expressFeeArr' => [//快递费
                    $this->province1 => 2.8,
                    $this->province2 => 2.8,
                    $this->province3 => 2.8
                ],
                'sellingPrice' => 9.53,//售价
            ],
            '蛇皮水管6分-10米'=>[
                'accessoryPrice' => 0.6,//配件价格
                'price' => 6.52,//价格
                'packFee' => 1.5,//打包费
                'expressFeeArr' => [//快递费
                    $this->province1 => 2.8,
                    $this->province2 => 2.8,
                    $this->province3 => 2.8
                ],
                'sellingPrice' => 14.78,//售价
            ],
            '蛇皮水管6分-15米'=>[
                'accessoryPrice' => 0.6,//配件价格
                'price' => 9.78,//价格
                'packFee' => 1.5,//打包费
                'expressFeeArr' => [//快递费
                    $this->province1 => 3.3,
                    $this->province2 => 3.3,
                    $this->province3 => 3.3
                ],
                'sellingPrice' => 19.81,//售价
            ],
            '蛇皮水管6分-20米'=>[
                'accessoryPrice' => 0.6,//配件价格
                'price' => 13.04,//价格
                'packFee' => 1.5,//打包费
                'expressFeeArr' => [//快递费
                    $this->province1 => 3.3,
                    $this->province2 => 3.3,
                    $this->province3 => 3.3
                ],
                'sellingPrice' => 24.23,//售价
            ],
            '蛇皮水管6分-25米'=>[
                'accessoryPrice' => 0.6,//配件价格
                'price' => 16.3,//价格
                'packFee' => 1.5,//打包费
                'expressFeeArr' => [//快递费
                    $this->province1 => 4,
                    $this->province2 => 4,
                    $this->province3 => 4
                ],
                'sellingPrice' => 28.99,//售价
            ],
            '蛇皮水管6分-30米'=>[
                'accessoryPrice' => 0.6,//配件价格
                'price' => 19.56,//价格
                'packFee' => 1.5,//打包费
                'expressFeeArr' => [//快递费
                    $this->province1 => 4,
                    $this->province2 => 4,
                    $this->province3 => 4
                ],
                'sellingPrice' => 33.68,//售价
            ],
            '蛇皮水管6分-35米'=>[
                'accessoryPrice' => 0.6,//配件价格
                'price' => 22.82,//价格
                'packFee' => 1.5,//打包费
                'expressFeeArr' => [//快递费
                    $this->province1 => 4,
                    $this->province2 => 4,
                    $this->province3 => 4
                ],
                'sellingPrice' => 38.04,//售价
            ],
            '蛇皮水管6分-40米'=>[
                'accessoryPrice' => 0.6,//配件价格
                'price' => 26.08,//价格
                'packFee' => 1.5,//打包费
                'expressFeeArr' => [//快递费
                    $this->province1 => 7.36,
                    $this->province2 => 8.8,
                    $this->province3 => 10.4
                ],
                'sellingPrice' => 45.59,//售价
            ],
            '蛇皮水管6分-45米'=>[
                'accessoryPrice' => 0.6,//配件价格
                'price' => 25.72,//价格
                'packFee' => 1.5,//打包费
                'expressFeeArr' => [//快递费
                    $this->province1 => 7.36,
                    $this->province2 => 8.8,
                    $this->province3 => 10.4
                ],
                'sellingPrice' => 48.79,//售价
            ],
            '蛇皮水管6分-50米'=>[
                'accessoryPrice' => 0.6,//配件价格
                'price' => 32.6,//价格
                'packFee' => 1.5,//打包费
                'expressFeeArr' => [//快递费
                    $this->province1 => 8.2,
                    $this->province2 => 10,
                    $this->province3 => 12
                ],
                'sellingPrice' => 55.15,//售价
            ],
            '蛇皮水管6分-55米'=>[
                'accessoryPrice' => 0.6,//配件价格
                'price' => 35.86,//价格
                'packFee' => 1.5,//打包费
                'expressFeeArr' => [//快递费
                    $this->province1 => 8.2,
                    $this->province2 => 10,
                    $this->province3 => 12
                ],
                'sellingPrice' => 59.84,//售价
            ],
            '蛇皮水管6分-60米'=>[
                'accessoryPrice' => 0.6,//配件价格
                'price' => 39.12,//价格
                'packFee' => 1.5,//打包费
                'expressFeeArr' => [//快递费
                    $this->province1 => 9.04,
                    $this->province2 => 11.2,
                    $this->province3 => 13.6
                ],
                'sellingPrice' => 65.99,//售价
            ],
            '蛇皮水管6分-70米'=>[
                'accessoryPrice' => 0.6,//配件价格
                'price' => 45.64,//价格
                'packFee' => 1.5,//打包费
                'expressFeeArr' => [//快递费
                    $this->province1 => 9.88,
                    $this->province2 => 12.4,
                    $this->province3 => 15.2
                ],
                'sellingPrice' => 76.87,//售价
            ],
            '蛇皮水管6分-80米'=>[
                'accessoryPrice' => 0.6,//配件价格
                'price' => 52.16,//价格
                'packFee' => 1.5,//打包费
                'expressFeeArr' => [//快递费
                    $this->province1 => 9.88,
                    $this->province2 => 12.4,
                    $this->province3 => 15.2
                ],
                'sellingPrice' => 83.77,//售价
            ],
            '蛇皮水管6分-90米'=>[
                'accessoryPrice' => 0.6,//配件价格
                'price' => 58.68,//价格
                'packFee' => 1.5,//打包费
                'expressFeeArr' => [//快递费
                    $this->province1 => 10.72,
                    $this->province2 => 13.6,
                    $this->province3 => 16.8
                ],
                'sellingPrice' => 100.43,//售价
            ],
            '蛇皮水管6分-100米'=>[
                'accessoryPrice' => 0.6,//配件价格
                'price' => 65.21,//价格
                'packFee' => 1.5,//打包费
                'expressFeeArr' => [//快递费
                    $this->province1 => 11.56,
                    $this->province2 => 14.8,
                    $this->province3 => 18.4
                ],
                'sellingPrice' => 106.01,//售价
            ],
    
    
            '蛇皮水管1寸-10厘米'=>[
                'accessoryPrice' => 0,//配件价格
                'price' => 0,//价格
                'packFee' => 1,//打包费
                'expressFeeArr' => [//快递费
                    $this->province1 => 2.8,
                    $this->province2 => 2.8,
                    $this->province3 => 2.8
                ],
                'sellingPrice' => 6.8,//售价
            ],
            '蛇皮水管1寸-5米'=>[
                'accessoryPrice' => 0.6,//配件价格
                'price' => 4.49,//价格
                'packFee' => 1.5,//打包费
                'expressFeeArr' => [//快递费
                    $this->province1 => 2.8,
                    $this->province2 => 2.8,
                    $this->province3 => 2.8
                ],
                'sellingPrice' => 12.19,//售价
            ],
            '蛇皮水管1寸-10米'=>[
                'accessoryPrice' => 0.6,//配件价格
                'price' => 8.98,//价格
                'packFee' => 1.5,//打包费
                'expressFeeArr' => [//快递费
                    $this->province1 => 3.3,
                    $this->province2 => 3.3,
                    $this->province3 => 3.3
                ],
                'sellingPrice' => 18.08,//售价
            ],
            '蛇皮水管1寸-15米'=>[
                'accessoryPrice' => 0.6,//配件价格
                'price' => 13.47,//价格
                'packFee' => 1.5,//打包费
                'expressFeeArr' => [//快递费
                    $this->province1 => 3.3,
                    $this->province2 => 3.3,
                    $this->province3 => 3.3
                ],
                'sellingPrice' => 24.05,//售价
            ],
            '蛇皮水管1寸-20米'=>[
                'accessoryPrice' => 0.6,//配件价格
                'price' => 17.96,//价格
                'packFee' => 1.5,//打包费
                'expressFeeArr' => [//快递费
                    $this->province1 => 4,
                    $this->province2 => 4,
                    $this->province3 => 4
                ],
                'sellingPrice' => 30.71,//售价
            ],
            '蛇皮水管1寸-25米'=>[
                'accessoryPrice' => 0.6,//配件价格
                'price' => 22.44,//价格
                'packFee' => 1.5,//打包费
                'expressFeeArr' => [//快递费
                    $this->province1 => 4,
                    $this->province2 => 4,
                    $this->province3 => 4
                ],
                'sellingPrice' => 37.83,//售价
            ],
            '蛇皮水管1寸-30米'=>[
                'accessoryPrice' => 0.6,//配件价格
                'price' => 26.93,//价格
                'packFee' => 1.5,//打包费
                'expressFeeArr' => [//快递费
                    $this->province1 => 7.36,
                    $this->province2 => 8.8,
                    $this->province3 => 10.4
                ],
                'sellingPrice' => 45.38,//售价
            ],
            '蛇皮水管1寸-35米'=>[
                'accessoryPrice' => 0.6,//配件价格
                'price' => 31.42,//价格
                'packFee' => 1.5,//打包费
                'expressFeeArr' => [//快递费
                    $this->province1 => 8.2,
                    $this->province2 => 10,
                    $this->province3 => 12
                ],
                'sellingPrice' => 52.79,//售价
            ],
            '蛇皮水管1寸-40米'=>[
                'accessoryPrice' => 0.6,//配件价格
                'price' => 35.91,//价格
                'packFee' => 1.5,//打包费
                'expressFeeArr' => [//快递费
                    $this->province1 => 8.2,
                    $this->province2 => 10,
                    $this->province3 => 12
                ],
                'sellingPrice' => 58.69,//售价
            ],
            '蛇皮水管1寸-45米'=>[
                'accessoryPrice' => 0.6,//配件价格
                'price' => 35.41,//价格
                'packFee' => 1.5,//打包费
                'expressFeeArr' => [//快递费
                    $this->province1 => 8.2,
                    $this->province2 => 10,
                    $this->province3 => 12
                ],
                'sellingPrice' => 65.99,//售价
            ],
            '蛇皮水管1寸-50米'=>[
                'accessoryPrice' => 0.6,//配件价格
                'price' => 44.89,//价格
                'packFee' => 1.5,//打包费
                'expressFeeArr' => [//快递费
                    $this->province1 => 9.04,
                    $this->province2 => 11.2,
                    $this->province3 => 13.6
                ],
                'sellingPrice' => 71.49,//售价
            ],
            '蛇皮水管1寸-55米'=>[
                'accessoryPrice' => 0.6,//配件价格
                'price' => 49.38,//价格
                'packFee' => 1.5,//打包费
                'expressFeeArr' => [//快递费
                    $this->province1 => 9.88,
                    $this->province2 => 12.4,
                    $this->province3 => 15.2
                ],
                'sellingPrice' => 80.39,//售价
            ],
            '蛇皮水管1寸-60米'=>[
                'accessoryPrice' => 0.6,//配件价格
                'price' => 53.87,//价格
                'packFee' => 1.5,//打包费
                'expressFeeArr' => [//快递费
                    $this->province1 => 10.72,
                    $this->province2 => 13.6,
                    $this->province3 => 16.8
                ],
                'sellingPrice' => 84.47,//售价
            ],
            '蛇皮水管1寸-70米'=>[
                'accessoryPrice' => 0.6,//配件价格
                'price' => 62.84,//价格
                'packFee' => 1.5,//打包费
                'expressFeeArr' => [//快递费
                    $this->province1 => 11.56,
                    $this->province2 => 14.8,
                    $this->province3 => 18.4
                ],
                'sellingPrice' => 100.74,//售价
            ],
            '蛇皮水管1寸-80米'=>[
                'accessoryPrice' => 0.6,//配件价格
                'price' => 71.82,//价格
                'packFee' => 1.5,//打包费
                'expressFeeArr' => [//快递费
                    $this->province1 => 12.4,
                    $this->province2 => 16,
                    $this->province3 => 20
                ],
                'sellingPrice' => 114.56,//售价
            ],
            '蛇皮水管1寸-90米'=>[
                'accessoryPrice' => 0.6,//配件价格
                'price' => 80.8,//价格
                'packFee' => 1.5,//打包费
                'expressFeeArr' => [//快递费
                    $this->province1 => 13.24,
                    $this->province2 => 17.2,
                    $this->province3 => 21.6
                ],
                'sellingPrice' => 128.63,//售价
            ],
            '蛇皮水管1寸-100米'=>[
                'accessoryPrice' => 0.6,//配件价格
                'price' => 89.78,//价格
                'packFee' => 1.5,//打包费
                'expressFeeArr' => [//快递费
                    $this->province1 => 14.08,
                    $this->province2 => 18.4,
                    $this->province3 => 23.2
                ],
                'sellingPrice' => 136.49,//售价
            ],
    
    
            '蛇皮水管1.2寸-10厘米'=>[
                'accessoryPrice' => 0,//配件价格
                'price' => 0,//价格
                'packFee' => 1,//打包费
                'expressFeeArr' => [//快递费
                    $this->province1 => 2.8,
                    $this->province2 => 2.8,
                    $this->province3 => 2.8
                ],
                'sellingPrice' => 10.8,//售价
            ],
            '蛇皮水管1.2寸-5米'=>[
                'accessoryPrice' => 0.6,//配件价格
                'price' => 8.98,//价格
                'packFee' => 1.5,//打包费
                'expressFeeArr' => [//快递费
                    $this->province1 => 3.3,
                    $this->province2 => 3.3,
                    $this->province3 => 3.3
                ],
                'sellingPrice' => 17.19,//售价
            ],
            '蛇皮水管1.2寸-10米'=>[
                'accessoryPrice' => 0.6,//配件价格
                'price' => 17.96,//价格
                'packFee' => 1.5,//打包费
                'expressFeeArr' => [//快递费
                    $this->province1 => 4,
                    $this->province2 => 4,
                    $this->province3 => 4
                ],
                'sellingPrice' => 29.99,//售价
            ],
            '蛇皮水管1.2寸-15米'=>[
                'accessoryPrice' => 0.6,//配件价格
                'price' => 26.93,//价格
                'packFee' => 1.5,//打包费
                'expressFeeArr' => [//快递费
                    $this->province1 => 7.36,
                    $this->province2 => 8.8,
                    $this->province3 => 10.4
                ],
                'sellingPrice' => 47.01,//售价
            ],
            '蛇皮水管1.2寸-20米'=>[
                'accessoryPrice' => 0.6,//配件价格
                'price' => 35.91,//价格
                'packFee' => 1.5,//打包费
                'expressFeeArr' => [//快递费
                    $this->province1 => 8.2,
                    $this->province2 => 10,
                    $this->province3 => 12
                ],
                'sellingPrice' => 58.99,//售价
            ],
            '蛇皮水管1.2寸-25米'=>[
                'accessoryPrice' => 0.6,//配件价格
                'price' => 44.89,//价格
                'packFee' => 1.5,//打包费
                'expressFeeArr' => [//快递费
                    $this->province1 => 9.04,
                    $this->province2 => 11.2,
                    $this->province3 => 13.6
                ],
                'sellingPrice' => 73.19,//售价
            ],
            '蛇皮水管1.2寸-30米'=>[
                'accessoryPrice' => 0.6,//配件价格
                'price' => 53.87,//价格
                'packFee' => 1.5,//打包费
                'expressFeeArr' => [//快递费
                    $this->province1 => 10.72,
                    $this->province2 => 13.6,
                    $this->province3 => 16.8
                ],
                'sellingPrice' => 83.35,//售价
            ],
            '蛇皮水管1.2寸-35米'=>[
                'accessoryPrice' => 0.6,//配件价格
                'price' => 62.84,//价格
                'packFee' => 1.5,//打包费
                'expressFeeArr' => [//快递费
                    $this->province1 => 11.56,
                    $this->province2 => 14.8,
                    $this->province3 => 18.4
                ],
                'sellingPrice' => 102.59,//售价
            ],
            '蛇皮水管1.2寸-40米'=>[
                'accessoryPrice' => 0.6,//配件价格
                'price' => 71.82,//价格
                'packFee' => 1.5,//打包费
                'expressFeeArr' => [//快递费
                    $this->province1 => 12.4,
                    $this->province2 => 16,
                    $this->province3 => 20
                ],
                'sellingPrice' => 117.99,//售价
            ],
            '蛇皮水管1.2寸-45米'=>[
                'accessoryPrice' => 0.6,//配件价格
                'price' => 70.82,//价格
                'packFee' => 1.5,//打包费
                'expressFeeArr' => [//快递费
                    $this->province1 => 12.4,
                    $this->province2 => 16,
                    $this->province3 => 20
                ],
                'sellingPrice' => 135.69,//售价
            ],
            '蛇皮水管1.2寸-50米'=>[
                'accessoryPrice' => 0.6,//配件价格
                'price' => 89.78,//价格
                'packFee' => 1.5,//打包费
                'expressFeeArr' => [//快递费
                    $this->province1 => 14.08,
                    $this->province2 => 18.4,
                    $this->province3 => 23.2
                ],
                'sellingPrice' => 139.79,//售价
            ],
        ];
    }

    /**
     * 报告列表
     */
    public function index(Request $request)
    {
        $keywords = $request->get('keywords') ?? '';
        $reportLists = ZhyReport::orderBy('id','desc')->paginate(config('page_size'));

        return view('admin.waterPipe.index', ['reportLists' => $reportLists,'keywords'=>$keywords]);

    }

    
    /**
     * 上传文件
     */
    public function upload(Request $request)
    {

        // $file = fopen($request->file('file'),"r");

        // $list = [];
        // while(! feof($file))
        // {
        //     $list[] = fgetcsv($file);
        // }

        // fclose($file);

        // dd($request->file('file')->getClientOriginalName());die;




        $file = $request->file('file');

        if(!$file->isValid()){

        }

        // dd($request->file('file')->getPathName());die;

        //转为数组
        $excelData = Excel::toArray([], $file)[0];

        $actualTotalPrice = 0;//实收总金额
        $receivableTotalPrice = 0;//应收总金额 货款总额
        
        foreach($excelData as $k => $v){
            if($k > 0){
                $productCode = $v[13];//商品编码
                $provinceCityDistrictStr = $v[5];//省市区
                $actualPrice = str_replace('￥','',$v[17]);//实收价格
                $number = $v[14];//数量

                // print_r($v[17]);
                // echo "<br>";
                // print_r((float)$actualPrice);
                // echo "<br>";

                // $actualPrice = (float)$actualPrice;

                $province = explode('/',$provinceCityDistrictStr)[0];//省份

                $productCodeArr = $this->productCodeList[$productCode];

                $expressFee = 0;
                foreach($productCodeArr['expressFeeArr'] as $k1 => $v1){
                    
                    if(strpos($k1,$province)!==false){
                        $expressFee = $v1;
                    }
                }

                if($expressFee == 0){
                    print_r($v);die;
                }

                //应收价格 货款金额
                $receivablePrice = $productCodeArr['accessoryPrice'] + $productCodeArr['price'] + $productCodeArr['packFee'] + $expressFee;//应收价格 = 配件+成本+打包+运费
                // $receivableTotalPrice += $productCodeArr['accessoryPrice'] + $productCodeArr['price'] + $productCodeArr['packFee'] + $expressFee;//应收价格 = 配件+成本+打包+运费

                // print_r($productCodeArr);

                $receivableTotalPrice += $receivablePrice * $number;
                

                $actualTotalPrice += $actualPrice;

                
            }
        }

        $profit = $actualTotalPrice - $receivableTotalPrice;

        return Response::response(['code' => 0, 'msg' => '上传成功','data'=>[
            'actualTotalPrice' => "$actualTotalPrice",
            'receivableTotalPrice' => "$receivableTotalPrice",
            'profit' => "$profit",
            'originalName' => $file->getClientOriginalName(),//返回原始的文件名
            ]]
        );
        

    }


    /**
     * 差异列表
     */
    public function diff(Request $request)
    {
        return view('admin.waterPipe.diff');
    }



    /**
     * 上传货款文件
     */
    public function huokuanUpload(Request $request)
    {

        $file = $request->file('file');

        if(!$file->isValid()){

        }

        // dd($request->file('file')->getPathName());die;

        //转为数组
        $excelData = Excel::toArray([], $file)[0];

        // print_r($excelData);die;
        

        $list = [];
        
        $k = 1;
        $yingshouzongji = 0;
        foreach($excelData as $k => $v){
            if($k > 0){

                if(isset($v[0])){
                    $yingshouzongji += $v[12];
                    $list[] = [
                        'orderNo' => $v[0],//订单号
                        'province' => $v[2],//省份
                        'number' => $v[3],//数量
                        'productCode' => $v[6],//商品编码
        
                        'peijianzongji' => $v[8],//配件总计
                        'chengbenzongji' => $v[9],//成本总计
                        'dabaozongji' => $v[10],//打包总计
                        'yunfeizongji' => $v[11],//运费总计
                        'yingshouzongji' => $v[12],//应收总计
                        'k' => $k++
                    ];
                }else{
                    $list[] = [
                        'orderNo' => '',//订单号
                        'province' =>'',//省份
                        'number' => '',//数量
                        'productCode' => '',//商品编码
        
                        'peijianzongji' => '',//配件总计
                        'chengbenzongji' => '',//成本总计
                        'dabaozongji' => '',//打包总计
                        'yunfeizongji' => '',//运费总计
                        'yingshouzongji' => "$yingshouzongji",//应收总计
                        'k' => $k++
                    ];
                }
                
            }
        }


        return Response::response(['code' => 0, 'msg' => '上传成功','data'=>[
            'list' => $list,
            ]]
        );
        

    }


    /**
     * 上传订单文件
     */
    public function dingdanUpload(Request $request)
    {

        $file = $request->file('file');

        if(!$file->isValid()){

        }

        // dd($request->file('file')->getPathName());die;

        //转为数组
        $excelData = Excel::toArray([], $file)[0];

        // print_r($excelData);die;
        

        $list = [];

        $actualTotalPrice = 0;//实收总金额
        $receivableTotalPrice = 0;//应收总金额 货款总额
        
        $k = 1;
        $yingshouzongji = 0;
        foreach($excelData as $k => $v){
            if($k > 0){

                $productCode = $v[13];//商品编码
                $provinceCityDistrictStr = $v[5];//省市区
                $actualPrice = str_replace('￥','',$v[17]);//实收价格
                $number = $v[14];//数量

                // print_r($v[17]);
                // echo "<br>";
                // print_r((float)$actualPrice);
                // echo "<br>";

                // $actualPrice = (float)$actualPrice;

                $province = explode('/',$provinceCityDistrictStr)[0];//省份

                $productCodeArr = $this->productCodeList[$productCode];

                $expressFee = 0;
                foreach($productCodeArr['expressFeeArr'] as $k1 => $v1){
                    
                    if(strpos($k1,$province)!==false){
                        $expressFee = $v1;
                    }
                }

                if($expressFee == 0){
                    print_r($v);die;
                }

                //应收价格 货款金额
                $receivablePrice = $productCodeArr['accessoryPrice'] + $productCodeArr['price'] + $productCodeArr['packFee'] + $expressFee;//应收价格 = 配件+成本+打包+运费
                // $receivableTotalPrice += $productCodeArr['accessoryPrice'] + $productCodeArr['price'] + $productCodeArr['packFee'] + $expressFee;//应收价格 = 配件+成本+打包+运费

                // print_r($productCodeArr);

                $peijianzongji = $productCodeArr['accessoryPrice'] * $number;
                $chengbenzongji = $productCodeArr['price'] * $number;
                $dabaozongji = $productCodeArr['packFee'] * $number;
                $yunfeizongji = $expressFee * $number;
                $yingshouzongji = $receivablePrice * $number;

                $receivableTotalPrice += $receivablePrice * $number;
                

                $actualTotalPrice += $actualPrice;


                $list[] = [
                    'orderNo' => $v[0],//订单号
                    'province' => $province,//省份
                    'number' => $number,//数量
                    'productCode' => $productCode,//商品编码
    
                    'peijianzongji' => "$peijianzongji",//配件总计
                    'chengbenzongji' => "$chengbenzongji",//成本总计
                    'dabaozongji' => "$dabaozongji",//打包总计
                    'yunfeizongji' => "$yunfeizongji",//运费总计
                    'yingshouzongji' => "$yingshouzongji",//应收总计
                    'k' => $k++
                ];
                
            }
        }

        $list[] = [
            'orderNo' => '',//订单号
            'province' =>'',//省份
            'number' => '',//数量
            'productCode' => '',//商品编码

            'peijianzongji' => '',//配件总计
            'chengbenzongji' => '',//成本总计
            'dabaozongji' => '',//打包总计
            'yunfeizongji' => '',//运费总计
            'yingshouzongji' => "$receivableTotalPrice",//应收总计
            'k' => $k++
        ];


        return Response::response(['code' => 0, 'msg' => '上传成功','data'=>[
            'list' => $list,
            ]]
        );
        

    }

    
    

}
